package com.gitee.wsl.collections.iterator


class ZipWithIndexIterator<T>(
    iterable: Iterable<T>
) : Iterator<Pair<T, Int>> {
    private val iterator: Iterator<T> = iterable.iterator()
    private var index = 0


    override fun hasNext(): Boolean {
        return this.iterator.hasNext()
    }

    override fun next(): Pair<T, Int> {
        try {
            return this.iterator.next() to this.index
        } finally {
            this.index += 1
        }
    }
}
